package com.ruoyi.mall.sms.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.sms.domain.SmsFlashPromotionProductRelation;
import com.ruoyi.mall.sms.service.ISmsFlashPromotionProductRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品限时购与商品关系Controller
 *
 * @author xuxing
 * @date 2021-02-09
 */
@RestController
@RequestMapping("/sms/flashPromotionProductRelation")
public class SmsFlashPromotionProductRelationController extends BaseController
{
    @Autowired
    private ISmsFlashPromotionProductRelationService smsFlashPromotionProductRelationService;

    /**
     * 查询商品限时购与商品关系列表
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionProductRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsFlashPromotionProductRelation smsFlashPromotionProductRelation)
    {
        startPage();
        List<SmsFlashPromotionProductRelation> list = smsFlashPromotionProductRelationService.selectSmsFlashPromotionProductRelationList(smsFlashPromotionProductRelation);
        return getDataTable(list);
    }

    /**
     * 导出商品限时购与商品关系列表
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionProductRelation:export')")
    @Log(title = "商品限时购与商品关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmsFlashPromotionProductRelation smsFlashPromotionProductRelation)
    {
        List<SmsFlashPromotionProductRelation> list = smsFlashPromotionProductRelationService.selectSmsFlashPromotionProductRelationList(smsFlashPromotionProductRelation);
        ExcelUtil<SmsFlashPromotionProductRelation> util = new ExcelUtil<SmsFlashPromotionProductRelation>(SmsFlashPromotionProductRelation.class);
        return util.exportExcel(list, "flashPromotionProductRelation");
    }

    /**
     * 获取商品限时购与商品关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionProductRelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsFlashPromotionProductRelationService.selectSmsFlashPromotionProductRelationById(id));
    }

    /**
     * 新增商品限时购与商品关系
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionProductRelation:add')")
    @Log(title = "商品限时购与商品关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<SmsFlashPromotionProductRelation> smsFlashPromotionProductRelationList)
    {
        return toAjax(smsFlashPromotionProductRelationService.insertSmsFlashPromotionProductRelation(smsFlashPromotionProductRelationList));
    }

    /**
     * 修改商品限时购与商品关系
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionProductRelation:edit')")
    @Log(title = "商品限时购与商品关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsFlashPromotionProductRelation smsFlashPromotionProductRelation)
    {
        return toAjax(smsFlashPromotionProductRelationService.updateSmsFlashPromotionProductRelation(smsFlashPromotionProductRelation));
    }

    /**
     * 删除商品限时购与商品关系
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionProductRelation:remove')")
    @Log(title = "商品限时购与商品关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsFlashPromotionProductRelationService.deleteSmsFlashPromotionProductRelationByIds(ids));
    }
}
